package com.boc.ewr.uniapp.api.controller;

import com.boc.ewr.bcimp.entity.Pro;
import com.boc.ewr.uniapp.api.service.INotificatDataService;
import com.boc.ewr.uniapp.api.vo.CaRateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author : Wzz
 * @create : 2023-06- 09- 10:43
 * @desc :
 */

@Api(tags = "生成下发通报数据")
@RestController
@RequestMapping("/uniapp/notificat")
@Slf4j
public class NotificatDataApiController {

    @Autowired
    private ISysBaseAPI sysBaseAPI;

    @Autowired
    private INotificatDataService notificatDataService;

    /**
     * 对账协议签约情况				Pro未签约/总数
     */
    @ApiOperation(value = "生成下发通报数据-对账协议签约情况", notes = "生成下发通报数据-对账协议签约情况")
    @GetMapping(value = "/getProSignStatus")
    public Result<List<CaRateVo>> getProSignStatus() {

        List<String> orgCodeList = new ArrayList<>();
        Set<String> orgCodeSetByLoginUser = sysBaseAPI.getOrgCodeSetByLoginUser(this.getLoginUser());
        if (orgCodeSetByLoginUser!=null) {
            orgCodeList = new ArrayList<>(orgCodeSetByLoginUser);
        }else {
            orgCodeList.add(this.getLoginUser().getOrgCode());
        }

        List<CaRateVo> proSignStatus = notificatDataService.getProSignStatus(orgCodeList);

        return Result.OK(proSignStatus);
    }


    /**
     * 对账回执率				回执查询清单中（有效回执）/余额对账单明细
     */
    @ApiOperation(value = "生成下发通报数据-对账回执率", notes = "生成下发通报数据-对账回执率")
    @GetMapping(value = "/getCaRtnRate")
    public Result<List<CaRateVo>> getCaRtnRate() {

        List<String> orgCodeList = new ArrayList<>();
        Set<String> orgCodeSetByLoginUser = sysBaseAPI.getOrgCodeSetByLoginUser(this.getLoginUser());
        if (orgCodeSetByLoginUser!=null) {
            orgCodeList = new ArrayList<>(orgCodeSetByLoginUser);
        }else {
            orgCodeList.add(this.getLoginUser().getOrgCode());
        }

        List<CaRateVo> caRtnRate = notificatDataService.getCaRtnRate(orgCodeList);

        return Result.OK(caRtnRate);
    }


    /**
     * 单一网银对账签约率
     * 	    单一网银签约率			网银签约率=网银渠道协议数/协议总数*100%	Pro
     * 	    新开账户签约网银渠道		网银签约率=网银渠道协议数/协议总数*100%	Pro
     */
    @ApiOperation(value = "生成下发通报数据-单一网银对账签约率", notes = "生成下发通报数据-单一网银对账签约率")
    @GetMapping(value = "/getEBankSignRate")
    public Result<Map<String, List<CaRateVo>>> getEBankSignRate() {

        List<String> orgCodeList = new ArrayList<>();
        Set<String> orgCodeSetByLoginUser = sysBaseAPI.getOrgCodeSetByLoginUser(this.getLoginUser());
        if (orgCodeSetByLoginUser!=null) {
            orgCodeList = new ArrayList<>(orgCodeSetByLoginUser);
        }else {
            orgCodeList.add(this.getLoginUser().getOrgCode());
        }

        Map<String, List<CaRateVo>> eBankSignRate = notificatDataService.getEBankSignRate(orgCodeList);

        return Result.OK(eBankSignRate);
    }


    /**
     * 网银对账回执率				回执查询清单中（有效回执）/余额对账单明细
     */
    @ApiOperation(value = "生成下发通报数据-单一网银对账签约率", notes = "生成下发通报数据-单一网银对账签约率")
    @GetMapping(value = "/getEBankRtnRate")
    public Result<List<CaRateVo>> getEBankRtnRate() {

        List<String> orgCodeList = new ArrayList<>();
        Set<String> orgCodeSetByLoginUser = sysBaseAPI.getOrgCodeSetByLoginUser(this.getLoginUser());
        if (orgCodeSetByLoginUser!=null) {
            orgCodeList = new ArrayList<>(orgCodeSetByLoginUser);
        }else {
            orgCodeList.add(this.getLoginUser().getOrgCode());
        }

        List<CaRateVo> eBankRtnRate = notificatDataService.getEBankRtnRate(orgCodeList);

        return Result.OK(eBankRtnRate);
    }

    private LoginUser getLoginUser() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return sysUser;
    }
}
